﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controller;
using Entity;
using iTextSharp.text;

namespace Web
{
    public partial class CustomerInvoiceDetail : System.Web.UI.Page
    {
        CustInvoiceController customerInvoiceController=new CustInvoiceController();
        DeliveryController deliveryController =new DeliveryController();
        Helper helper = new Helper(); 
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (Request.QueryString["custInvoiceId"] != null)
            {
                try
                {
                    EditButton.Visible = false;
                    int customerInvoiceId = Convert.ToInt32(Request.QueryString["custInvoiceId"]);
                    CustomerInvoiceEntity customerInvoiceEntity =
                        customerInvoiceController.FindCustomerInvoiceById(customerInvoiceId);
                    InvoiceNoLable.Text = customerInvoiceEntity.CustomerInvoiceNo;
                    CustomerLabel.Text = customerInvoiceEntity.CustomerShortName;

                    AddressLabel.Text = customerInvoiceEntity.CustomerAddress;
                    ZipCodeLabel.Text = customerInvoiceEntity.CustomerZipCode;
                    PaidLabel.Text = customerInvoiceEntity.Paid;
                    DateLabel.Text = customerInvoiceEntity.CustomerInvoiceDate.ToString("d MMM, yyyy");

                    IList<DeliveryEntity> deliveryEntities =
                        deliveryController.FindDeliveryByInvoiceId(customerInvoiceId);
                    CustomerInvoiceItemsGridView.DataSource = deliveryEntities;
                    CustomerInvoiceItemsGridView.DataBind();
                    Session["PrepareToGeneratePDF"] = deliveryEntities;
                    Session["PONo"] = deliveryEntities[0].PoNo;
                }

                catch (Exception)
                {
                    //Session["Massage"] = "No such customer invoice.";
                    Session["FlashMessage"] = "Error: No Such Customer Invoice!";
                    Session["FlashMessageType"] = "error";
                    Response.Redirect("CustomerInvoiceList.aspx",false);
                }
            }
            else
            {
                Response.Redirect("CustomerInvoiceList.aspx",false);
            }
            this.PreRender += new EventHandler(UpdateFlashMessage);
        }
        private void UpdateFlashMessage(object sender, EventArgs e)
        {
            helper.ShowFlashMessage(FlashMessageLabel);
        }
        protected void EditButton_Click(object sender, EventArgs e)
        {

        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            int customerInvoiceId = Convert.ToInt32(Request.QueryString["custInvoiceId"]);
            int msg = customerInvoiceController.DeleteCustomerInvoiceById(customerInvoiceId);
            if (msg == 1)
            {
                //this.MsgLabel.Text = "Delete successful!";
                Session["FlashMessage"] = "Success: Delete Successful!";
                Session["FlashMessageType"] = "success";
            }
            if (msg == 0)
            {
                //this.MsgLabel.Text = "Delete unsuccessful!";
                Session["FlashMessage"] = "Error: Delete Unsuccessful!";
                Session["FlashMessageType"] = "error";
            }
        }


        //*****************Generate Customer Invoice PDF**************************//
        //protected void PDFButton_Click(object sender, EventArgs e)
        //{
        //    if (Session["PrepareToGeneratePDF"] != null)
        //    {
        //        //Set PDF size
        //        iTextSharp.text.Rectangle rec = new Rectangle(900, 1250); //A4


        //        //Create PDF
        //        iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);

        //        //Create Pdfwriter object for document
        //        //Create PDF name
        //        string PDFName = "Invoice" + InvoiceNoLable.Text + ".pdf";
        //        iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
        //                                                  new System.IO.FileStream(
        //                                                      Server.MapPath("./") + "PDF/" + PDFName,
        //                                                      System.IO.FileMode.Create));

        //        doc.Open();
        //        //Add an image object
        //        iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance(Server.MapPath("logo.jpg"));

        //        //Add a table
        //        iTextSharp.text.Table table = new iTextSharp.text.Table(10);
        //        table.BorderWidth = 1;
        //        table.BorderColor = new Color(0, 0, 0);
        //        table.Padding = 5;
        //        table.Spacing = 5;

        //        Cell logo = new Cell(jpeg);
        //        logo.Header = true;
        //        logo.Colspan = 10;
        //        logo.HorizontalAlignment = 1;

        //        table.AddCell(logo);

        //        Cell gst = new Cell("Co. & GST Registration Number: 20-0105271-M");
        //        gst.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
        //        gst.Colspan = 6;
        //        gst.HorizontalAlignment = 0;
        //        table.AddCell(gst);

        //        //Create a phrase that contain font style
        //        Phrase myPhrase = new Phrase("TAX INVOICE", FontFactory.GetFont(FontFactory.TIMES_BOLD, 14, Font.BOLD));
        //        Cell title = new Cell(myPhrase);
        //        title.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
        //        title.Colspan = 4;
        //        title.HorizontalAlignment = 1;
        //        table.AddCell(title);


        //        Cell customer = new Cell("Customer");
        //        customer.Colspan = 6;
        //        customer.HorizontalAlignment = 0;
        //        table.AddCell(customer);


        //        Cell invoiceInfo = new Cell();
        //        string invoiceNo = this.InvoiceNoLable.Text;
        //        string date = this.DateLabel.Text;
        //        Paragraph i1 = new Paragraph("Invoice No.: " + invoiceNo);
        //        Paragraph i2 = new Paragraph("Date: " + date);
        //        Paragraph i3 = new Paragraph("Yr PO No.: -");
        //        Paragraph i4 = new Paragraph("Terms: WIRE-TRANSFER");
        //        Paragraph i5 = new Paragraph("Currency: USD");
        //        invoiceInfo.Add(i1);
        //        invoiceInfo.Add(i2);
        //        invoiceInfo.Add(i3);
        //        invoiceInfo.Add(i4);
        //        invoiceInfo.Add(i5);
        //        invoiceInfo.Colspan = 4;
        //        invoiceInfo.Rowspan = 6;
        //        table.AddCell(invoiceInfo);

        //        Cell customerInfo = new Cell();
        //        Paragraph p1 = new Paragraph("Company:   SONNAX INDUSTRIES, INC.");
        //        Paragraph p2 = new Paragraph("Address:   P.O. BOX 440 AUTOMATIC DRIVE");
        //        Paragraph p3 = new Paragraph("City:      BELLLOWS FALLS");
        //        Paragraph p4 = new Paragraph("State:     VT ZIP: 05101-0440");
        //        Paragraph p5 = new Paragraph("Attention: Ms. Debra Rocca");
        //        Paragraph p6 = new Paragraph("Phone:     802-463-9722");
        //        Paragraph p7 = new Paragraph("Tariff Code: 8481.90.9080");
        //        customerInfo.Add(p1);
        //        customerInfo.Add(p2);
        //        customerInfo.Add(p3);
        //        customerInfo.Add(p4);
        //        customerInfo.Add(p5);
        //        customerInfo.Add(p6);
        //        customerInfo.Add(p7);
        //        customerInfo.Colspan = 6;
        //        customerInfo.Rowspan = 5;

        //        table.AddCell(customerInfo);

        //        Cell qty = new Cell("Qty");
        //        qty.Colspan = 1;
        //        table.AddCell(qty);
        //        Cell no = new Cell("No");
        //        no.Colspan = 2;
        //        table.AddCell(no);
        //        Cell name = new Cell("Name");
        //        name.Colspan = 2;
        //        table.AddCell(name);
        //        Cell rev = new Cell("Rev.");
        //        rev.Colspan = 1;
        //        table.AddCell(rev);
        //        Cell price = new Cell("Unit Price");
        //        price.Colspan = 2;
        //        table.AddCell(price);
        //        Cell total = new Cell("TOTAL");
        //        total.Colspan = 2;
        //        table.AddCell(total);

        //        foreach (GridViewRow r in CustomerInvoiceItemsGridView.Rows)
        //        {

        //            string gvNo = r.Cells[0].Text;
        //            string gvName = r.Cells[1].Text;
        //            string gvQty = r.Cells[3].Text;
        //            string gvRev = r.Cells[2].Text;
        //            string gvPrice = r.Cells[4].Text;
        //            string gvTotal = r.Cells[5].Text;
        //            Cell qty1 = new Cell(gvQty);
        //            qty1.Colspan = 1;
        //            table.AddCell(qty1);
        //            Cell no1 = new Cell(gvNo);
        //            no1.Colspan = 2;
        //            table.AddCell(no1);
        //            Cell name1 = new Cell(gvName);
        //            name1.Colspan = 2;
        //            table.AddCell(name1);
        //            Cell rev1 = new Cell(gvRev);
        //            rev1.Colspan = 1;
        //            table.AddCell(rev1);
        //            Cell price1 = new Cell("$" + gvPrice);
        //            price1.Colspan = 2;
        //            table.AddCell(price1);
        //            Cell total1 = new Cell("$" + gvTotal);
        //            total1.Colspan = 2;
        //            table.AddCell(total1);

        //        }

        //        Cell shippingAddress = new Cell();
        //        shippingAddress.Colspan = 5;
        //        shippingAddress.Rowspan = 3;
        //        Paragraph sa = new Paragraph("Shipping Address");
        //        Paragraph asabove = new Paragraph("AS ABOVE");
        //        Paragraph country = new Paragraph("Country of Origin: Singapore");
        //        shippingAddress.Add(sa);
        //        shippingAddress.Add(asabove);
        //        shippingAddress.Add(country);
        //        table.AddCell(shippingAddress);

        //        Cell amountSumary = new Cell();
        //        amountSumary.Colspan = 5;
        //        amountSumary.Rowspan = 3;
        //        amountSumary.HorizontalAlignment = 2;
        //        //string subTotal = "Sub Total: $" + this.SubTotalLabel.Text;
        //        //string sAndI = "Shipping & Insurance: $" + this.ShippingAndInsuranceTextBox.Text;
        //        //string totalAmount = "TOTAL: $" + this.TotalLabel.Text;
        //        //Paragraph pSubTotal = new Paragraph(subTotal);
        //        //Paragraph pSAndI = new Paragraph(sAndI);
        //        //Paragraph pTotalAmount = new Paragraph(totalAmount);
        //        //amountSumary.Add(pSubTotal);
        //        //amountSumary.Add(pSAndI);
        //        //amountSumary.Add(pTotalAmount);
        //        table.AddCell(amountSumary);

        //        Cell shippingMode = new Cell();
        //        shippingMode.Colspan = 5;
        //        shippingMode.Rowspan = 3;
        //        //string weight = "Shipping Weight: " + this.WeightTextBox.Text;
        //        Paragraph sm = new Paragraph("Shipping Mode");
        //        //Paragraph pWeight = new Paragraph(weight);
        //        Paragraph ups = new Paragraph("UPS Freight Collects");
        //        shippingMode.Add(sm);
        //        //shippingMode.Add(pWeight);
        //        shippingMode.Add(ups);
        //        table.AddCell(shippingMode);

        //        Cell sign = new Cell();
        //        sign.Colspan = 5;
        //        sign.Rowspan = 3;
        //        table.AddCell(sign);

        //        Cell footer = new Cell();
        //        Phrase footerPhrase =
        //            new Phrase("11 Kian Teck Avenue Singapore 628899 tel>65-6261-5607 e-mail>mstan@skyfab.com.sg",
        //                       FontFactory.GetFont(FontFactory.TIMES, 10));
        //        footer.Add(footerPhrase);
        //        footer.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
        //        footer.Colspan = 10;
        //        footer.HorizontalAlignment = 1;
        //        footer.Header = true;
        //        table.AddCell(footer);
        //        doc.Add(table);
        //        doc.Close();
        //        Response.Redirect("PDF/" + PDFName);
        //    }
        //    else
        //    {
        //        //SubmitFirstLabel.Text = "Please submit customer invoice first!";
        //        Session["FlashMessage"] = "Error: Please Submit Customer Invoice First!";
        //        Session["FlashMessageType"] = "error";
        //    }
        //}

        //********************Generate Package PDF******************************//
        protected void PackagePDFButton_Click(object sender, EventArgs e)
        {

            {
                if (Session["PrepareToGeneratePDF"] != null)
                {

                    iTextSharp.text.Rectangle rec = new Rectangle(900, 1250);

                    iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);


                    string pdfName = "Package_" + InvoiceNoLable.Text.Trim() + ".pdf";
                    iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
                                                              new System.IO.FileStream(
                                                                  Server.MapPath("./") + "PDF/" + pdfName,
                                                                  System.IO.FileMode.Create));

                    doc.Open();


                    iTextSharp.text.Table table = new iTextSharp.text.Table(11);
                    table.BorderWidth = 1;
                    table.BorderColor = new Color(0, 0, 0);
                    table.Padding = 5;
                    table.Spacing = 5;

                    Cell customer = new Cell("Customer");
                    customer.Colspan = 7;
                    customer.HorizontalAlignment = 0;
                    table.AddCell(customer);


                    Cell deliveryInfo = new Cell();
                    string invoiceNo = this.InvoiceNoLable.Text;
                    string deliveryDate = System.DateTime.Now.ToString("d MMM, yyyy");
                    string poNo = Session["PONo"].ToString();
                    Paragraph i1 = new Paragraph("Invoice No.: " + invoiceNo);
                    Paragraph i2 = new Paragraph("Date: " + deliveryDate);
                    Paragraph i3 = new Paragraph("PO No.: " + poNo);

                    deliveryInfo.Add(i1);
                    deliveryInfo.Add(i2);
                    deliveryInfo.Add(i3);
                    deliveryInfo.Colspan = 4;
                    deliveryInfo.Rowspan = 6;
                    table.AddCell(deliveryInfo);

                    Cell customerInfo = new Cell();
                    Paragraph p1 = new Paragraph("Company:   SONNAX INDUSTRIES, INC.");
                    Paragraph p2 = new Paragraph("Address:   P.O. BOX 440 AUTOMATIC DRIVE");
                    Paragraph p3 = new Paragraph("City:      BELLLOWS FALLS");
                    Paragraph p4 = new Paragraph("State:     VT ZIP: 05101-0440");
                    Paragraph p5 = new Paragraph("Attention: Ms. Debra Rocca");
                    Paragraph p6 = new Paragraph("Phone:     802-463-9722");
                    Paragraph p7 = new Paragraph("Tariff Code: 8481.90.9080");
                    customerInfo.Add(p1);
                    customerInfo.Add(p2);
                    customerInfo.Add(p3);
                    customerInfo.Add(p4);
                    customerInfo.Add(p5);
                    customerInfo.Add(p6);
                    customerInfo.Add(p7);
                    customerInfo.Colspan = 7;
                    customerInfo.Rowspan = 5;

                    table.AddCell(customerInfo);

                    Cell no = new Cell("No");
                    no.Colspan = 2;
                    table.AddCell(no);

                    Cell name = new Cell("Name");
                    name.Colspan = 2;
                    table.AddCell(name);

                    Cell rev = new Cell("Rev.");
                    rev.Colspan = 1;
                    table.AddCell(rev);

                    Cell batchNo = new Cell("Batch No");
                    batchNo.Colspan = 2;
                    table.AddCell(batchNo);

                    Cell requestQty = new Cell("R-Qty");
                    requestQty.Colspan = 1;
                    table.AddCell(requestQty);

                    Cell deliveryQty = new Cell("D-Qty");
                    deliveryQty.Colspan = 1;
                    table.AddCell(deliveryQty);

                    Cell requestedDate = new Cell("Requested Date");
                    requestedDate.Colspan = 2;
                    table.AddCell(requestedDate);



                    IList<DeliveryEntity> deliveryEntities = Session["PrepareToGeneratePDF"] as IList<DeliveryEntity>;
                    foreach (DeliveryEntity deliveryEntity in deliveryEntities)
                    {

                        string pkNo = deliveryEntity.ProductNo;
                        string pkName = deliveryEntity.ProductName;
                        int pkRQty = deliveryEntity.Quantity;
                        string pkRev = deliveryEntity.Revision;
                        string pkRequestDate = deliveryEntity.RequestedDate.ToString("d MMM, yyyy");
                        string pkBatchNo = deliveryEntity.BatchNo;
                        int pkDQty = deliveryEntity.Quantity;
                        Cell vno = new Cell(pkNo);
                        vno.Colspan = 2;
                        table.AddCell(vno);

                        Cell vname = new Cell(pkName);
                        vname.Colspan = 2;
                        table.AddCell(vname);

                        Cell vrev = new Cell(pkRev);
                        vrev.Colspan = 1;
                        table.AddCell(vrev);

                        Cell vbatchNo = new Cell(pkBatchNo);
                        vbatchNo.Colspan = 2;
                        table.AddCell(vbatchNo);

                        Cell vrequestQty = new Cell(pkRQty.ToString());
                        vrequestQty.Colspan = 1;
                        table.AddCell(vrequestQty);

                        Cell vdeliveryQty = new Cell(pkDQty.ToString());
                        vdeliveryQty.Colspan = 1;
                        table.AddCell(vdeliveryQty);

                        Cell vrequestedDate = new Cell(pkRequestDate);
                        vrequestedDate.Colspan = 2;
                        table.AddCell(vrequestedDate);

                    }

                    Cell shippingAddress = new Cell();
                    shippingAddress.Colspan = 6;
                    shippingAddress.Rowspan = 3;
                    Paragraph sa = new Paragraph("Shipping Address");
                    Paragraph asabove = new Paragraph("AS ABOVE");
                    Paragraph country = new Paragraph("Country of Origin: Singapore");
                    shippingAddress.Add(sa);
                    shippingAddress.Add(asabove);
                    shippingAddress.Add(country);
                    table.AddCell(shippingAddress);



                    Cell shippingMode = new Cell();
                    shippingMode.Colspan = 5;
                    shippingMode.Rowspan = 3;
                    //string weight = "Shipping Weight: " + this.WeightTextBox.Text;
                    string weight = "Shipping Weight: ";
                    Paragraph sm = new Paragraph("Shipping Mode");
                    Paragraph pWeight = new Paragraph(weight);
                    Paragraph ups = new Paragraph("UPS Freight Collects");
                    shippingMode.Add(sm);
                    shippingMode.Add(pWeight);
                    shippingMode.Add(ups);
                    table.AddCell(shippingMode);

                    Cell footer = new Cell();
                    Phrase footerPhrase =
                        new Phrase("11 Kian Teck Avenue Singapore 628899 tel>65-6261-5607 e-mail>mstan@skyfab.com.sg",
                                   FontFactory.GetFont(FontFactory.TIMES, 10));
                    footer.Add(footerPhrase);
                    footer.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
                    footer.Colspan = 11;
                    footer.HorizontalAlignment = 1;
                    footer.Header = true;
                    table.AddCell(footer);
                    doc.Add(table);
                    doc.Close();
                    Response.Redirect("PDF/" + pdfName);

                }
                else
                {
                    //SubmitFirstLabel.Text = "Please submit customer invoice first!";
                    Session["FlashMessage"] = "Error: Please Submit Customer Invoice First!";
                    Session["FlashMessageType"] = "error";
                }


            }
        }
        //****************************Genreate Item List PDF**************************//
        protected void ItemPDFButton_Click(object sender, EventArgs e)
        {

            {
                if (Session["PrepareToGeneratePDF"] != null)
                {
                    iTextSharp.text.Rectangle rec = new Rectangle(900, 1250);


                    iTextSharp.text.Document doc = new iTextSharp.text.Document(rec, 1, 1, 105, 45);

                    string pdfName = "List_" + InvoiceNoLable.Text.Trim() + ".pdf";
                    iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
                                                              new System.IO.FileStream(
                                                                  Server.MapPath("./") + "PDF/" + pdfName,
                                                                  System.IO.FileMode.Create));

                    doc.Open();



                    IList<DeliveryEntity> deliveryEntities = Session["PrepareToGeneratePDF"] as IList<DeliveryEntity>;

                    int count = 0;
                    foreach (DeliveryEntity deliveryEntity in deliveryEntities)
                    {
                        iTextSharp.text.Table table = new iTextSharp.text.Table(14);
                        table.BorderWidth = 1;
                        table.BorderColor = new Color(0, 0, 0);
                        table.Padding = 1;
                        table.Spacing = 1;


                        string pno = deliveryEntity.ProductNo;
                        int pdeliveryQty = deliveryEntity.Quantity;
                        string poNo = deliveryEntity.PoNo;
                        string invoiceNo = this.InvoiceNoLable.Text.Trim();
                        string batchNo = deliveryEntity.BatchNo;
                        string rev = deliveryEntity.Revision;
                        string rDate = deliveryEntity.RequestedDate.ToString("dd/MMM/yyyy");
                        string sDate = System.DateTime.Now.ToString("dd/MMM/yyyy");
                        int orderQty = deliveryEntity.RequestQty;
                        int lot = deliveryEntity.Lot;
                        string customerFullName = deliveryEntity.Customer;


                        //*******Line 1******************//
                        Paragraph header1 = new Paragraph("SKY FAB SOLUTIONS PTE LTD");
                        header1.Font.IsBold();
                        Paragraph header2 = new Paragraph("PACKING SLIP");
                        header2.Font.IsBold();
                        Cell headerCell = new Cell();
                        headerCell.Colspan = 9;
                        headerCell.Add(header1);
                        headerCell.Add(header2);
                        table.AddCell(headerCell);

                        Cell rightPartNoCell = new Cell(pno);
                        rightPartNoCell.Colspan = 3;
                        table.AddCell(rightPartNoCell);

                        Cell rightQtyCell = new Cell(pdeliveryQty.ToString());
                        rightQtyCell.Rowspan = 2;
                        rightQtyCell.Colspan = 2;
                        table.AddCell(rightQtyCell);

                        //*******Line 2******************//
                        Cell toTitleCell = new Cell("TO:");
                        toTitleCell.Colspan = 2;
                        table.AddCell(toTitleCell);

                        Cell toCell = new Cell(customerFullName);
                        toCell.Colspan = 7;

                        table.AddCell(toCell);

                        Cell rightSCOCell = new Cell("SCO-" + batchNo);
                        rightSCOCell.Colspan = 3;

                        table.AddCell(rightSCOCell);

                        //*******Line 3******************//

                        Cell partNoTitleCell = new Cell("PART NO:");

                        partNoTitleCell.Colspan = 2;
                        table.AddCell(partNoTitleCell);

                        Cell partNoCell = new Cell(pno);
                        partNoCell.Colspan = 3;
                        table.AddCell(partNoCell);

                        Cell revTitleCell = new Cell("REV:");
                        revTitleCell.Colspan = 2;
                        table.AddCell(revTitleCell);

                        Cell revCell = new Cell(rev);
                        revCell.Colspan = 2;
                        table.AddCell(revCell);

                        Cell rightBlankCell = new Cell();

                        rightBlankCell.Colspan = 5;
                        rightBlankCell.Rowspan = 6;

                        table.AddCell(rightBlankCell);

                        //*******Line 4******************//
                        Cell PONoTitleCell = new Cell("PO NO:");
                        PONoTitleCell.Colspan = 2;
                        table.AddCell(PONoTitleCell);

                        Cell PONoCell = new Cell(poNo);
                        PONoCell.Colspan = 3;
                        table.AddCell(PONoCell);

                        Cell DueDateTitleCell = new Cell("DUE DATE:");
                        DueDateTitleCell.Colspan = 2;
                        table.AddCell(DueDateTitleCell);

                        Cell DueDateCell = new Cell(rDate);
                        DueDateCell.Colspan = 2;
                        table.AddCell(DueDateCell);



                        //*******Line 5******************//
                        Cell invoiceNoTitleCell = new Cell("INV NO:");
                        invoiceNoTitleCell.Colspan = 2;
                        table.AddCell(invoiceNoTitleCell);

                        Cell invoiceNoCell = new Cell(invoiceNo);
                        invoiceNoCell.Colspan = 3;
                        table.AddCell(invoiceNoCell);

                        Cell shipDateTitleCell = new Cell("SHIP DATE:");
                        shipDateTitleCell.Colspan = 2;
                        table.AddCell(shipDateTitleCell);

                        Cell shipDateCell = new Cell(sDate);
                        shipDateCell.Colspan = 2;
                        table.AddCell(shipDateCell);



                        //*******Line 6******************//
                        Cell batchNoTitleCell = new Cell("JOB NO:");
                        batchNoTitleCell.Colspan = 2;
                        table.AddCell(batchNoTitleCell);

                        Cell batchNoCell = new Cell("SCO- " + batchNo);
                        batchNoCell.Colspan = 3;
                        table.AddCell(batchNoCell);

                        Cell lotTitleCell = new Cell("LOT QTY:");
                        lotTitleCell.Colspan = 2;
                        table.AddCell(lotTitleCell);

                        Cell lotCell = new Cell(lot + " pcs");
                        lotCell.Colspan = 2;
                        table.AddCell(lotCell);



                        //*******Line 7******************//

                        Cell rQTYTitleCell = new Cell("ORDER QTY:");
                        rQTYTitleCell.Colspan = 2;
                        table.AddCell(rQTYTitleCell);

                        Cell rQTYCell = new Cell(orderQty.ToString() + " PCS");
                        rQTYCell.Colspan = 3;
                        table.AddCell(rQTYCell);

                        Cell totalQTYTitleCell = new Cell("TOTAL QTY:");
                        totalQTYTitleCell.Colspan = 2;
                        table.AddCell(totalQTYTitleCell);

                        Cell totalQTYCell = new Cell(pdeliveryQty.ToString() + " pcs");
                        totalQTYCell.Colspan = 2;
                        table.AddCell(totalQTYCell);




                        //*******Line 8******************//
                        Cell remarkTitleCell = new Cell("REMARKS:");
                        remarkTitleCell.Colspan = 2;

                        table.AddCell(remarkTitleCell);

                        Cell remarkCell = new Cell();

                        remarkCell.Colspan = 7;
                        table.AddCell(remarkCell);

                        Cell pagebreak = new Cell(" ");
                        pagebreak.Border = 0;
                        pagebreak.Colspan = 14;

                        table.AddCell(pagebreak);

                        doc.Add(table);
                        count++;

                        if (count % 5 == 0)
                        {
                            doc.NewPage();
                        }





                    }

                    doc.Close();
                    Response.Redirect("PDF/" + pdfName);


                }
                else
                {
                    //SubmitFirstLabel.Text = "Please submit customer invoice first!";
                    Session["FlashMessage"] = "Error: Please Submit Customer Invoice First!";
                    Session["FlashMessageType"] = "error";
                }

            }
        }
    }
}